<#include "/common/header.html" >
<link href="/css/zTreeStyle/zTreeStyle.css" rel="stylesheet">
<body class=" gray-bg">
<div class="wrapper wrapper-content  animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <form action="" id="pressmForm" class="form-horizontal">
                           <div class="form-group">
                                <label class="col-sm-2 control-label">选择权限</label>
                                <div class="col-sm-10">
								<!-- <#list pressmList as pressm>
									<label><input type="checkbox" ${(pressm.userId!=null)?string('checked="checked"','') } value="${pressm.id}" name="pressmId"> ${pressm.pressmName} </label> 
								</#list> -->
                            <ul id="treeDemo" class="ztree"></ul>
								 </div>
                            </div>
                             <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                	<input type="hidden" name="userId" value="${userId}">
                                    <button class="btn btn-primary" type="submit">保存内容</button>
                                    <button class="btn btn-warning" type="button" onclick="history.back()">返回列表</button>
                                </div>
                            </div>
                            
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <#include "/common/footer.html" >
	<script src="/js/plugins/ztree/jquery.ztree.core.min.js"></script>
	<script src="/js/plugins/ztree/jquery.ztree.excheck.min.js"></script>
	<script type="text/javascript">
	$(function(){
		var setting = {
				check: {
					enable: true
				},
				data: {
					simpleData: {
						enable: true
					}
				}
			};
		$(document).ready(function(){
			$.ajax({
				url:"/sys/user/pressm/${userId}",
				type:"POST",
				dataType:"json",
				success:function(data){
					var zNodes =[];
					for(var i in data){
						zNodes[i] = {id:data[i].id,pId:data[i].parentId,name:data[i].pressmName,checked:data[i].userId!=null,open:data[i].parentId == 0};
					}
					$.fn.zTree.init($("#treeDemo"), setting, zNodes);
				},
				error:function(){
					wxLayer.alert(data.responseJSON.message);
				},
			})
		});
		$("#pressmForm").submit(function(){
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			var sNodes = zTree.getCheckedNodes();
			for(var i in sNodes){
				$("#pressmForm").append("<input type='hidden' value='"+sNodes[i].id+"' name='pressmId' >");
			}
			
			console.log($("#pressmForm").serialize() );
			$.ajax({
				url:"/sys/user/pressm/save",
				type:"POST",
				data:$("#pressmForm").serialize(),
				dataType:"json",
				success:function(data){
					wxLayer.alert(data.message,function(){
						if(data.status)
							location.href="/sys/user/list";
					});
				},
				error:function(){
					wxLayer.alert(data.responseJSON.message);
				},
			})
			return false;
		})
	});
	
	</script>
</body>
</html>
